import csv

header = ['name', 'area', 'country_code2', 'country_code3']
data = ['Afghanistan', 652090, 'AF', 'AFG']
rows = [
    {'name': 'Albania',
    'area': 28748,
    'country_code2': 'AL',
    'country_code3': 'ALB'},
    {'name': 'Algeria',
    'area': 2381741,
    'country_code2': 'DZ',
    'country_code3': 'DZA'},
    {'name': 'American Samoa',
    'area': 199,
    'country_code2': 'AS',
    'country_code3': 'ASM'}
]

with open('write_csv.csv', 'w', encoding='utf8') as f:
    # writer = csv.writer(f)
    # writer.writerow(header)
    # writer.writerow(data)

    writer = csv.DictWriter(f, header)
    writer.writeheader()
    writer.writerows(rows)